import axios from "axios";

// 创建axios实例
const serve=axios.create({
    baseURL:'https: //www.fastmock.site/mock/bf1fcb3c2e2945669c2c8deecb8e09b8/api',
    timeout:5000,
    headers:{
        "Content-Type":"application/json;charset=UTF-8"
    }
})

// 请求拦截器
serve.interceptors.request.use(config=>{
    config.headers=config.headers||{}
    if(localStorage.getItem('token')){
        config.headers.token=localStorage.getItem('token')||''
    }
    
    return config
})

// 响应拦截器
axios.interceptors.response.use(response=>{
    const code:number=response.data
    
    if(code !==200){
        return Promise.reject(response.data)
    }
    return response.data
},error => {
    console.log(error);
    
})

export default serve